package org.come.lianhua;

import com.tool.btn.FormsOnOffBtn;
import com.tool.tcp.NewPart;
import com.tool.tcpimg.*;
import com.updateNew.MyIsif;
import org.apache.commons.lang.StringUtils;
import org.come.Frame.NewRefiningJframe;
import org.come.Frame.SuitBaptizeJframe;
import org.come.Frame.WorkshopRefiningJframe;
import org.come.Jpanel.RefinersJpanel;
import org.come.Jpanel.RefiningEquiJpanel;
import org.come.Jpanel.RefiningEquiJpanel2;
import org.come.bean.QualityClBean;
import org.come.bean.Skill;
import org.come.entity.Goodstable;
import org.come.starcard.JframeStarCardMain;
import org.come.summonequip.JframeSummonEquipMain;
import org.come.until.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.ImageObserver;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

public class AutoMaticRefiningJpanel extends JPanel {
    private ImageIcon iconBack;
    private JScrollPane paneList;
    private AotoMaticRefiningBtn assistantBtn, start;
    private AutoMaticRefiningView optionJpanel;
    public JLabel displaymodetext;
    private int leftFlag;
    private List<AttributeVo> attributeVoList;
    private String[] lianHua = {"属性一", "属性二", "属性三", "属性四", "属性五", "特技一", "特技二"};
    private RichLabel richLabel;

    private JLabel msgBox;

    private Color color = new Color(56, 53, 46, 238);
    private Color color2 = new Color(0, 0, 0, 128);
    private RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(60, 50, 100, 20, 7, 7);
    private int count = 0;
    public AutoMaticRefiningJpanel() {
        this.setPreferredSize(new Dimension(416, 516));
        this.setOpaque(false);
        this.setLayout(null);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        final FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 999);
        offBtn.setBounds(416-35, 10, 25, 25);
        this.add(offBtn);
        } else {
            final FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/8/ss83.png", 1, 999);
            offBtn.setBounds(397, 3, 17, 17);
            this.add(offBtn);
        }
        msgBox = new JLabel() {
            @Override
            protected void paintComponent(final Graphics g) {
                if (richLabel != null)
                    richLabel.paint(g);
            }
        };
        if ("水墨UI".equals(style)) {
        msgBox.setBounds(40, 285, 350, 100);
        this.add(msgBox);
        (this.displaymodetext = new JLabel("炼化")).setForeground(Color.white);
        this.displaymodetext.setFont(UIUtils.TEXT_FONT1);
        displaymodetext.setHorizontalAlignment(0);
        displaymodetext.setVerticalTextPosition(0);
        displaymodetext.setBounds(60, 55, 100, 20);
        this.add((Component) this.displaymodetext);
        final String[] displaymodeData = {"炼化", "炼器", "配饰重铸", "星卡神通", "兽装重悟技能", "兽装重洗属性", "套装洗炼"};
        this.optionJpanel = new AutoMaticRefiningView(105, 120, displaymodeData);
        } else {
            msgBox.setBounds(40, 285, 350, 100);
            this.add(msgBox);
            (this.displaymodetext = new JLabel("炼化")).setForeground(Color.white);
            this.displaymodetext.setFont(UIUtils.TEXT_FONT1);
            displaymodetext.setHorizontalAlignment(0);
            displaymodetext.setVerticalTextPosition(0);
            displaymodetext.setBounds(60, 30, 100, 20);
            this.add((Component) this.displaymodetext);
            final String[] displaymodeData = {"炼化", "炼器", "配饰重铸", "星卡神通", "兽装重悟技能", "兽装重洗属性", "套装洗炼"};
            this.optionJpanel = new AutoMaticRefiningView(105, 120, displaymodeData);
        }
        this.optionJpanel.getJlist().addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                final String getname = (String) AutoMaticRefiningJpanel.this.optionJpanel.getJlist().getSelectedValue();
                AutoMaticRefiningJpanel.this.optionJpanel.setVisible(false);
                AutoMaticRefiningJpanel.this.leftFlag = 1;
                if (!getname.equals(AutoMaticRefiningJpanel.this.displaymodetext.getText())) {
                    AutoMaticRefiningJpanel assistantJpanel = AutoMaticRefiningJframe.getAssistantJframe().getAssistantJpanel();
                    for (AttributeVo attributeVo : assistantJpanel.getAttributeVoList()) {
                        assistantJpanel.remove(attributeVo.getJ1());
                        assistantJpanel.remove(attributeVo.getJ2());
                        assistantJpanel.remove(attributeVo.getAttributeName());
                    }
                    String style = MyIsif.getStyle();
                    if ("水墨UI".equals(style)) {
                    attributeVoList.clear();
                    richLabel = null;

                    if (getname.equals("炼化")) {
                        lianHua = new String[]{"属性一", "属性二", "属性三", "属性四", "属性五", "特技一", "特技二"};
                        String msg = "#K调出炼化面板在点击运行即可开始自动炼化#r如果需要锁定属性请在炼化面板进行#R锁定#K特技属性只需填写#R特技名称#r#K可通过#R|#K符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                        initLianHua(lianHua, msg);
                    } else if (getname.equals("炼器")) {
                        AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);

                        lianHua = new String[]{"属性一", "属性二", "属性三", "属性四", "属性五"};
                        String msg = "#K打开炼器面板在点击运行即可开始自动炼化#r如果需要锁定属性请在面板进行锁定#r可通过#R|#K符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                        initLianHua(lianHua, msg);
                    } else if (getname.equals("星卡神通")) {
                        AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);

                        lianHua = new String[]{"资质", "属性一", "属性二", "神通"};
                        String msg = "#K打开星录->重铸->重洗面板在点击运行即可开始自动洗星卡#r星阵属性只需填写星阵名称即可如#R(赤马|青龙)#K等等#r第一排资质要求#K后面填入#R资质#K二字，后面填写数字";
                        initLianHua(lianHua, msg);
                    } else if (getname.equals("配饰重铸")) {
                        AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                        lianHua = new String[]{"属性要求", "基础属性", "黄字抗性", "绿字属性一", "绿字属性二"};
                        String msg = "#K请将材料放置#R作坊#K面板上在点击运行即可开始自动炼化属性要求填写(根骨要求/灵性要求/力量要求/敏捷要求)不填写则无要求#r属性只需填写字段名(洗戒指#R黄字抗性不需要填写)#K可通过#R|#K符号同时匹配多个属性#r例:属性字段1属性字段2";
                        initLianHua(lianHua, msg);
                    } else if (getname.equals("兽装重悟技能")) {
                        AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                        lianHua = new String[]{"觉醒技", "星级"};
                        String msg = "#K请将材料放置#R兽装洗练#K面板上在点击运行即可开始自动洗炼#r觉醒技填写名称即可#K#r多个需求则用#R|#K分隔#r例:一击毙命|法力灵动";
                        initLianHua(lianHua, msg);
                        attributeVoList.get(1).getJ1().setText("星级");
                    } else if (getname.equals("兽装重洗属性")) {
                        AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                        lianHua = new String[]{"基础属性","属性一", "属性二", "属性三"};
                        String msg = "#K调出炼化面板在点击运行即可开始自动炼化#r如果需要锁定属性请在炼化面板进行#R锁定#K特技属性只需填写#R特技名称#r#K可通过#R|#K符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                        initLianHua(lianHua, msg);
                    } else if (getname.equals("套装洗炼")) {
                        AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                        lianHua = new String[]{"属性一", "属性二"};
                        String msg = "#K调出炼化面板在点击运行即可开始自动炼化#r如果需要锁定属性请在炼化面板进行#R锁定#K特技属性只需填写#R特技名称#r#K可通过#R|#K符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                        initLianHua(lianHua, msg);
                    }
                    } else {
                        attributeVoList.clear();
                        richLabel = null;

                        if (getname.equals("炼化")) {
                            lianHua = new String[]{"属性一", "属性二", "属性三", "属性四", "属性五", "特技一", "特技二"};
                            String msg = "#W调出炼化面板在点击运行即可开始自动炼化#r如果需要锁定属性请在炼化面板进行#R锁定#W特技属性只需填写#R特技名称#r#W可通过#R|#W符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                            initLianHua(lianHua, msg);
                        } else if (getname.equals("炼器")) {
                            AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);

                            lianHua = new String[]{"属性一", "属性二", "属性三", "属性四", "属性五"};
                            String msg = "#W打开炼器面板在点击运行即可开始自动炼化#r如果需要锁定属性请在面板进行锁定#r可通过#R|#W符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                            initLianHua(lianHua, msg);
                        } else if (getname.equals("星卡神通")) {
                            AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);

                            lianHua = new String[]{"资质", "属性一", "属性二", "神通"};
                            String msg = "#W打开星录->重铸->重洗面板在点击运行即可开始自动洗星卡#r星阵属性只需填写星阵名称即可如#R(赤马|青龙)#W等等#r第一排资质要求#W后面填入#R资质#W二字，后面填写数字";
                            initLianHua(lianHua, msg);
                        } else if (getname.equals("配饰重铸")) {
                            AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                            lianHua = new String[]{"属性要求", "基础属性", "黄字抗性", "绿字属性一", "绿字属性二"};
                            String msg = "#W请将材料放置#R作坊#W面板上在点击运行即可开始自动炼化属性要求填写(根骨要求/灵性要求/力量要求/敏捷要求)不填写则无要求#r属性只需填写字段名(洗戒指#R黄字抗性不需要填写)#W可通过#R|#W符号同时匹配多个属性#r例:属性字段1属性字段2";
                            initLianHua(lianHua, msg);
                        } else if (getname.equals("兽装重悟技能")) {
                            AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                            lianHua = new String[]{"觉醒技", "星级"};
                            String msg = "#W请将材料放置#R兽装洗练#W面板上在点击运行即可开始自动洗炼#r觉醒技填写名称即可#W#r多个需求则用#R|#W分隔#r例:一击毙命|法力灵动";
                            initLianHua(lianHua, msg);
                            attributeVoList.get(1).getJ1().setText("星级");
                        } else if (getname.equals("兽装重洗属性")) {
                            AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                            lianHua = new String[]{"基础属性","属性一", "属性二", "属性三"};
                            String msg = "#W调出炼化面板在点击运行即可开始自动炼化#r如果需要锁定属性请在炼化面板进行#R锁定#W特技属性只需填写#R特技名称#r#W可通过#R|#W符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                            initLianHua(lianHua, msg);
                        } else if (getname.equals("套装洗炼")) {
                            AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                            lianHua = new String[]{"属性一", "属性二"};
                            String msg = "#W调出炼化面板在点击运行即可开始自动炼化#r如果需要锁定属性请在炼化面板进行#R锁定#W特技属性只需填写#R特技名称#r#W可通过#R|#W符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";
                            initLianHua(lianHua, msg);
                        }
                    }
                    AutoMaticRefiningJpanel.this.displaymodetext.setText(getname);
                }
            }
        });
        this.optionJpanel.setVisible(false);
        optionJpanel.setBounds(60, 75, 120, 120);
        this.add((Component) this.optionJpanel);
        if ("水墨UI".equals(style)) {
        (this.assistantBtn = new AotoMaticRefiningBtn("inkimg/button/8.png", 1, UIUtils.COLOR_BTNXUANXIANGKA, UIUtils.TEXT_FONT81, "", this, 0))
                .setBounds(160, 57, 18, 18);
        this.add((Component) this.assistantBtn);

        (this.start = new AotoMaticRefiningBtn("inkImg/newbutton/B21.png", 1, UIUtils.COLOR_BTNXUANXIANGKA, UIUtils.TEXT_FONT81, "运行", this, 1))
                .setBounds(180, 420, 79, 24);
        this.add((Component) this.start);
        } else {
            (this.assistantBtn = new AotoMaticRefiningBtn("inkimg/hongmu/25.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT81, "", this, 0))
                    .setBounds(160, 32, 18, 18);
            this.add((Component) this.assistantBtn);

            (this.start = new AotoMaticRefiningBtn("inkImg/hongmu/60_26.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT81, "运行", this, 1))
                    .setBounds(200, 357, 60, 26);
            this.add((Component) this.start);
        }
        lianHua = new String[]{"属性一", "属性二", "属性三", "属性四", "属性五", "特技一", "特技二"};
        String msg = "#W调出炼化面板在点击运行即可开始自动炼化#r如果需要锁定属性请在炼化面板进行#R锁定#W特技属性只需填写#R特技名称#r#W可通过#R|#W符号同时匹配多个属性。例:忽视抗混|加强风#r#R(注意别写错别字)";

        initLianHua(lianHua, msg);
    }

    private void initLianHua(String[] lianHua, String msg) {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        if (attributeVoList == null)
            attributeVoList = new ArrayList<>();
        int x = 130, y = 100;
        Font font = new Font("微软雅黑", 0, 16);
        for (int i = 0; i < lianHua.length; i++) {
            AttributeVo attributeVo = new AttributeVo();
            JLabel attrName = new JLabel(this.lianHua[i]);
            attrName.setBounds(x - 70, y + i * 30, 100, 20);
            attrName.setFont(UIUtils.TEXT_FONT1);
            attributeVo.setAttributeName(attrName);
            this.add(attrName);

            JTextField j1 = new JTextField() {
                @Override
                protected void paintComponent(final Graphics g) {
                    Graphics2D g2d = (Graphics2D) g.create();
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                    RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(0, 0, this.getWidth(), this.getHeight(), 5, 5);
                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                    g2d.setColor(color);
                    g2d.fill(roundedRectangle);
                    g2d.setColor(Color.white);
                    super.paintComponent(g);
                }
            };
            j1.setForeground(Color.white);
            j1.setBackground(UIUtils.Color_BACK);
            j1.setBorder(BorderFactory.createEmptyBorder());
            j1.setCaretColor(Color.WHITE);
            j1.setFont(font);
            j1.setBounds(x, y + i * 30, 100, 20);
            attributeVo.setJ1(j1);
            this.add(j1);

            JTextField j2 = new JTextField() {
                @Override
                protected void paintComponent(final Graphics g) {
                    Graphics2D g2d = (Graphics2D) g.create();
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                    RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(0, 0, this.getWidth(), this.getHeight(), 7, 7);
                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                    g2d.setColor(color);
                    g2d.fill(roundedRectangle);
                    g2d.setColor(Color.white);
                    super.paintComponent(g);

                }
            };
            j2.setForeground(Color.white);
            j2.setBackground(UIUtils.Color_BACK);
            j2.setBorder(BorderFactory.createEmptyBorder());
            j2.setCaretColor(Color.WHITE);
            j2.setFont(font);
            j2.setBounds(x + 120, y + i * 30, 100, 20);
            attributeVo.setJ2(j2);
            this.add(j2);
            attributeVoList.add(attributeVo);
        }


        AttributeVo attributeVo = attributeVoList.get(attributeVoList.size() - 1);
        Rectangle bounds = attributeVo.getJ1().getBounds();
        if (displaymodetext.getText().equals("星卡神通"))
            msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
        else if (displaymodetext.getText().equals("配饰重铸")) {
            msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
        } else if (displaymodetext.getText().equals("兽装重悟技能")) {
            msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
        } else if (displaymodetext.getText().equals("兽装重洗属性")) {
            msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
        } else if (displaymodetext.getText().equals("套装洗炼")) {
            msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
        } else
            msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
        richLabel = new RichLabel();
        richLabel.addText(msg);
        richLabel.setSize(msgBox.getWidth(), msgBox.getHeight());
        } else  {
            if (attributeVoList == null)
                attributeVoList = new ArrayList<>();
            int x = 130, y = 60;
            Font font = new Font("微软雅黑", 0, 16);
            for (int i = 0; i < lianHua.length; i++) {
                AttributeVo attributeVo = new AttributeVo();
                JLabel attrName = new JLabel(this.lianHua[i]);
                attrName.setBounds(x - 70, y + i * 30, 100, 20);
                attrName.setFont(UIUtils.TEXT_FONT1);
                attrName.setForeground(Color.white); // 设置红色字体
                attributeVo.setAttributeName(attrName);
                this.add(attrName);

                JTextField j1 = new JTextField() {
                    @Override
                    protected void paintComponent(final Graphics g) {
                        Graphics2D g2d = (Graphics2D) g.create();
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                        RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(0, 0, this.getWidth(), this.getHeight(), 5, 5);
                        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                        g2d.setColor(color2);
                        g2d.fill(roundedRectangle);
                        g2d.setColor(Color.white);
                        super.paintComponent(g);
                    }
                };
                j1.setForeground(Color.white);
                j1.setBackground(UIUtils.Color_BACK);
                j1.setBorder(BorderFactory.createEmptyBorder());
                j1.setCaretColor(Color.WHITE);
                j1.setFont(font);
                j1.setBounds(x, y + i * 30, 100, 20);
                attributeVo.setJ1(j1);
                this.add(j1);

                JTextField j2 = new JTextField() {
                    @Override
                    protected void paintComponent(final Graphics g) {
                        Graphics2D g2d = (Graphics2D) g.create();
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                        RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(0, 0, this.getWidth(), this.getHeight(), 7, 7);
                        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                        g2d.setColor(color2);
                        g2d.fill(roundedRectangle);
                        g2d.setColor(Color.white);
                        super.paintComponent(g);

                    }
                };
                j2.setForeground(Color.white);
                j2.setBackground(UIUtils.Color_BACK);
                j2.setBorder(BorderFactory.createEmptyBorder());
                j2.setCaretColor(Color.WHITE);
                j2.setFont(font);
                j2.setBounds(x + 120, y + i * 30, 100, 20);
                attributeVo.setJ2(j2);
                this.add(j2);
                attributeVoList.add(attributeVo);
            }


            AttributeVo attributeVo = attributeVoList.get(attributeVoList.size() - 1);
            Rectangle bounds = attributeVo.getJ1().getBounds();
            if (displaymodetext.getText().equals("星卡神通"))
                msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
            else if (displaymodetext.getText().equals("配饰重铸")) {
                msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
            } else if (displaymodetext.getText().equals("兽装重悟技能")) {
                msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
            } else if (displaymodetext.getText().equals("兽装重洗属性")) {
                msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
            } else if (displaymodetext.getText().equals("套装洗炼")) {
                msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
            } else
                msgBox.setBounds(60, (int) bounds.getY() + 50, 310, 475 - (int) bounds.getY());
            richLabel = new RichLabel();
            richLabel.addText(msg);
            richLabel.setSize(msgBox.getWidth(), msgBox.getHeight());
        }
    }

    public void detectionProperties(QualityClBean clBean) {
        count +=1;
        List<AttributeVo> collect = attributeVoList.stream().filter(item -> item.getJ1().getText() != null && item.getJ1().getText().length() >= 1).collect(Collectors.toList());
        RefiningEquiJpanel EJpanel = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel()
                .getCardJpanel().getEquiJpanel();
        Integer res[] = new Integer[attributeVoList.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = 0;
        }
        String newAttr = clBean.getNewAttr();
        if(newAttr==null){
            return;
        }
        if (newAttr.contains("特技")) {
            String[] split = newAttr.split("特技");
            String[] tjs = split[1].split("=");
            for (String s : tjs) {
                if (StringUtils.isBlank(s))
                    continue;
                Skill skill = UserMessUntil.getSkillId(s);
                if (skill != null)
                    split[0] += "&" + skill.getSkillname() + "=1";
            }
            newAttr = split[0];
        }

        if (newAttr.contains("星阵属性")) {
            String[] split = newAttr.split("星阵属性");
            String[] tjs = split[1].split("=");
            if (tjs.length == 3) {
                split[0] += tjs[1] + "=1";
            }
            newAttr = split[0];
        }
        String[] split = newAttr.split("&");


        int index = -1;
        for (AttributeVo attributeVo : attributeVoList) {
            index += 1;
            if (StringUtils.isBlank(attributeVo.getJ1().getText()))
                continue;
            if (start.getText().equals("运行"))
                return;
            long count = Arrays.stream(res).filter(item -> item == 1).count();
            if (count == collect.size()) {
                start.setText("运行");
                return;
            }
            String text = attributeVo.getJ1().getText();
            if (StringUtils.isBlank(text))
                continue;

            String[] vs = text.split("\\|");

            for (int i = 0; i < vs.length; i++) {
                Double attrNumber = 0d;
                if (StringUtils.isNotBlank(attributeVo.getJ2().getText())) {
                    attrNumber = Double.parseDouble(attributeVo.getJ2().getText().replace(" ", ""));
                }
                int k = -1;
                //检索包含字段(属性一)
                if (newAttr.contains(vs[i])) {
                    for (int i1 = 1; i1 < split.length; i1++) {
                        if (split[i1].startsWith(vs[i])) {
                            double v = Double.parseDouble(split[i1].split("=")[1]);
                            if (attrNumber != 0d && v >= attrNumber) {
                                k = i1;
                                res[index] = 1;
                                split[i1] = "";
                                break;
                            } else if (attrNumber == 0) {
                                k = i;
                                res[index] = 1;  //提出已经检索过的属性
                                split[i1] = "";
                                break;
                            }
                        }
                    }
                    if (k != -1) break;
                    else continue;
                    //提出已经检索过的属性
                }
            }
        }

        long sum = Arrays.stream(res).filter(item -> item == 1).count();
        if (sum == collect.size()) {
            start.setText("运行");
            return;
        }
        try {
            Thread.sleep(100);
        } catch (Exception e) {
        }
        if (displaymodetext.getText().equals("炼化")) {
            String v = RefiningUtil.detection(EJpanel.goods, EJpanel.getType());
            if (v.equals("炼化装备") || v.equals("炼化仙器") || v.equals("炼化神兵")) {
                if (start.getText().equals("停止"))
                    NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().getOperBtn3().nochoose(null);
            }
        } else if (displaymodetext.getText().equals("炼器")) {
            final RefinersJpanel rJpanel = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getRefinersJpanel();
            final String v = rJpanel.detection();
            if (v.equals("炼器")) {
                if (start.getText().equals("停止"))
                    NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().getOperBtn3().nochoose(null);
//                    NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().getOperBtn3().nochoose(null);
            }
        } else if (displaymodetext.getText().equals("星卡神通")) {
            int smallType = JframeStarCardMain.getJframeSummonEquipMain().getJpanelStarCardMain().getSmallType();

            if (smallType == 3) {
                if (start.getText().equals("停止"))
                    JframeStarCardMain.getJframeSummonEquipMain().getJpanelStarCardMain().caoZuoStarCard();
//                    NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().getOperBtn3().nochoose(null);
//                    NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().getOperBtn3().nochoose(null);
            }
        } else if (displaymodetext.getText().equals("套装洗炼")) {

            if (start.getText().equals("停止"))
                SuitBaptizeJframe.getSuitBaptizeJframe().getBaptizeJpanel().getBaptizeBtn1().nochoose(null);
        }
    }


    public void petEquiDetectionProperties(QualityClBean clBean) {

        count +=1;
        List<AttributeVo> collect = attributeVoList.stream().filter(item -> item.getJ1().getText() != null && item.getJ1().getText().length() >= 1).collect(Collectors.toList());
        RefiningEquiJpanel EJpanel = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel()
                .getCardJpanel().getEquiJpanel();
        Integer res[] = new Integer[attributeVoList.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = 0;
        }
        String newAttr = clBean.getNewAttr();
        if (newAttr.contains("觉醒技")) {
            String[] split = newAttr.split("觉醒技");
            String[] tjs = split[1].split("&");
            for (String s : tjs) {
                if (StringUtils.isBlank(s))
                    continue;
                Skill skill = UserMessUntil.getSkillId(s);
                if (skill != null) {
                    split[0] += "&" + skill.getSkillname() + "=1";
                    continue;
                }
                split[0] += "&星级=" + s;
                break;

            }
            newAttr = split[0];
        }

        String[] split = newAttr.split("&");


        int index = -1;
        for (AttributeVo attributeVo : attributeVoList) {
            index += 1;
            if (StringUtils.isBlank(attributeVo.getJ1().getText()))
                continue;
            if (start.getText().equals("运行"))
                return;
            long count = Arrays.stream(res).filter(item -> item == 1).count();
            if (count == collect.size()) {
                start.setText("运行");
                return;
            }
            String text = attributeVo.getJ1().getText();
            if (StringUtils.isBlank(text))
                continue;

            String[] vs = text.split("\\|");

            for (int i = 0; i < vs.length; i++) {
                Double attrNumber = 0d;
                if (StringUtils.isNotBlank(attributeVo.getJ2().getText())) {
                    attrNumber = Double.parseDouble(attributeVo.getJ2().getText().replace(" ", ""));
                }
                int k = -1;
                //检索包含字段(属性一)
                if (newAttr.contains(vs[i])) {
                    for (int i1 = 1; i1 < split.length; i1++) {
                        if (split[i1].startsWith(vs[i])) {
                            double v = Double.parseDouble(split[i1].split("=")[1]);
                            if (attrNumber != 0d && v >= attrNumber) {
                                k = i1;
                                res[index] = 1;
                                split[i1] = "";
                                break;
                            } else if (attrNumber == 0) {
                                k = i;
                                res[index] = 1;  //提出已经检索过的属性
                                split[i1] = "";
                                break;
                            }
                        }
                    }
                    if (k != -1) break;
                    else continue;
                    //提出已经检索过的属性
                }
            }
        }

        long sum = Arrays.stream(res).filter(item -> item == 1).count();
        if (sum == collect.size()) {
            start.setText("运行");
            return;
        }
        try {
            Thread.sleep(100);
        } catch (Exception e) {
        }
        if (displaymodetext.getText().equals("兽装重悟技能")) {
            JframeSummonEquipMain.getJframeSummonEquipMain().getJpanelSummonEquipMain().getAckBtn().nochoose(null);
        }
    }

    public void petShidetectionProperties(Goodstable goodstable) {
        count +=1;
        if (start.getText().equals("运行"))
            return;
        if (goodstable != null) {
            Goodstable[] goods = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel2().getGoods();
            goods[0] = goodstable;
            JLabel[] labGoods = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel2().getLabGoods();
            labGoods[0].setIcon((Icon) GoodsListFromServerUntil.imgpathAdaptive(goodstable.getSkin(), 49, 49));
        } else {
            Goodstable[] goods = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel2().getGoods();
            String detection = RefiningUtil.detection(goods, 2);
            if (detection.equals("佩饰重铸")) {
                WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel2().getWorkshopBtn().nochoose(null);
                return;
            }
        }
        List<AttributeVo> collect = attributeVoList.stream().filter(item -> item.getJ1().getText() != null && item.getJ1().getText().length() >= 1).collect(Collectors.toList());
        RefiningEquiJpanel2 EJpanel = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel2();
        Integer res[] = new Integer[attributeVoList.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = 0;
        }
        String newAttr = goodstable.getValue();

        String[] split = newAttr.split("\\|");

        String attr = "";
        String sxyq = "";
        String jcsx = "";
        String kxyq = "";
        for (String s : split) {
            String[] split1 = s.split("=");
            if (split1[0].equals("灵性要求") || split1[0].equals("力量要求") || split1[0].equals("根骨要求") || split1[0].equals("敏捷要求"))
                sxyq = s;
            else if (split1[0].equals("灵性") || split1[0].equals("力量") || split1[0].equals("根骨") || split1[0].equals("敏捷"))
                jcsx = s;
            else if (s.startsWith("抗"))
                kxyq = s;
            else if (s.startsWith("炼化属性")) {
                attr = s;
            }
        }
        attr += "&" + sxyq + "&" + jcsx;
        String[] jcsxs = kxyq.split("=");

        if (StringUtils.isNotBlank(attributeVoList.get(2).getJ1().getText())) {
            String[] split1 = attributeVoList.get(2).getJ1().getText().split("\\|");

            for (String s : split1) {
                if (s.equals(jcsxs[0])) {
                    if (StringUtils.isBlank(attributeVoList.get(2).getJ2().getText())) {
                        res[2] = 1;
                        break;
                    } else if (Integer.parseInt(jcsxs[1]) >= Integer.parseInt(attributeVoList.get(2).getJ2().getText())) {
                        res[2] = 1;
                        break;
                    } else {
                        res[2] = 0;
                        break;
                    }

                }
            }
        } else
            res[2] = 0;

        split = attr.split("&");
        int index = -1;
        for (AttributeVo attributeVo : attributeVoList) {
            index += 1;
            if (index == 2)
                continue;
            if (StringUtils.isBlank(attributeVo.getJ1().getText()))
                continue;
            if (start.getText().equals("运行"))
                return;
            long count = Arrays.stream(res).filter(item -> item == 1).count();
            if (count == collect.size()) {
                start.setText("运行");
                return;
            }
            String text = attributeVo.getJ1().getText();
            if (StringUtils.isBlank(text))
                continue;

            String[] vs = text.split("\\|");

            for (int i = 0; i < vs.length; i++) {
                Double attrNumber = 0d;
                if (StringUtils.isNotBlank(attributeVo.getJ2().getText())) {
                    attrNumber = Double.parseDouble(attributeVo.getJ2().getText().replace(" ", ""));
                }
                int k = -1;
                //检索包含字段(属性一)
                if (newAttr.contains(vs[i])) {
                    for (int i1 = 1; i1 < split.length; i1++) {
                        if (split[i1].startsWith(vs[i])) {
                            double v = Double.parseDouble(split[i1].split("=")[1]);
                            if (attrNumber != 0d && v >= attrNumber) {
                                k = i1;
                                res[index] = 1;
                                split[i1] = "";
                                break;
                            } else if (attrNumber == 0) {
                                k = i;
                                res[index] = 1;  //提出已经检索过的属性
                                split[i1] = "";
                                break;
                            }
                        }
                    }
                    if (k != -1) break;
                    else continue;
                    //提出已经检索过的属性
                }
            }
        }

        long sum = Arrays.stream(res).filter(item -> item == 1).count();
        if (sum == collect.size()) {
            start.setText("运行");
            return;
        }
        try {
            Thread.sleep(250);
        } catch (Exception e) {
        }
        if (displaymodetext.getText().equals("配饰重铸")) {
            Goodstable[] goods = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel2().getGoods();
            String detection = RefiningUtil.detection(goods, 2);
            if (detection.equals("佩饰重铸")) {
                WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel2().getWorkshopBtn().nochoose(null);
            }
        }
    }


    public void petShidetectionPropertiesAttr(Goodstable goodstable) {

        count +=1;
        List<AttributeVo> collect = attributeVoList.stream().filter(item -> item.getJ1().getText() != null && item.getJ1().getText().length() >= 1).collect(Collectors.toList());
        RefiningEquiJpanel EJpanel = WorkshopRefiningJframe.getWorkshopRefiningJframe().getWorkshopRefiningJpanel()
                .getCardJpanel().getEquiJpanel();
        Integer res[] = new Integer[attributeVoList.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = 0;
        }

        String s = goodstable.getValue().split("\\|")[3];
        String newAttr = AccessSuitMsgUntil.getExtra(goodstable.getValue(), "炼化属性");
        newAttr +=("&"+s);
        String[] split = newAttr.split("&");


        int index = -1;
        for (AttributeVo attributeVo : attributeVoList) {
            index += 1;
            if (StringUtils.isBlank(attributeVo.getJ1().getText()))
                continue;
            if (start.getText().equals("运行"))
                return;
            long count = Arrays.stream(res).filter(item -> item == 1).count();
            if (count == collect.size()) {
                start.setText("运行");
                return;
            }
            String text = attributeVo.getJ1().getText();
            if (StringUtils.isBlank(text))
                continue;

            String[] vs = text.split("\\|");

            for (int i = 0; i < vs.length; i++) {
                Double attrNumber = 0d;
                if (StringUtils.isNotBlank(attributeVo.getJ2().getText())) {
                    attrNumber = Double.parseDouble(attributeVo.getJ2().getText().replace(" ", ""));
                }
                int k = -1;
                //检索包含字段(属性一)
                if (newAttr.contains(vs[i])) {
                    for (int i1 = 1; i1 < split.length; i1++) {
                        if (split[i1].startsWith(vs[i])) {
                            double v = Double.parseDouble(split[i1].split("=")[1]);
                            if (attrNumber != 0d && v >= attrNumber) {
                                k = i1;
                                res[index] = 1;
                                split[i1] = "";
                                break;
                            } else if (attrNumber == 0) {
                                k = i;
                                res[index] = 1;  //提出已经检索过的属性
                                split[i1] = "";
                                break;
                            }
                        }
                    }
                    if (k != -1) break;
                    else continue;
                    //提出已经检索过的属性
                }
            }
        }

        long sum = Arrays.stream(res).filter(item -> item == 1).count();
        if (sum == collect.size()) {
            start.setText("运行");
            return;
        }
        try {
            Thread.sleep(150);
        } catch (Exception e) {
        }
        if (displaymodetext.getText().equals("兽装重洗属性")) {
            JframeSummonEquipMain.getJframeSummonEquipMain().getJpanelSummonEquipMain().getAckBtn().nochoose(null);
        }
    }

    public static int getCount(final String source, final String sub) {
        int count = 0;
        final int length = source.length() - sub.length();
        int i = 0;
        while (i < length) {
            final String sourceBak = source.substring(i, i + sub.length());
            final int index = sourceBak.indexOf(sub);
            if (index != -1) {
                ++count;
            }
            ++i;
        }
        return count;
    }

    private NewPart part;

    @Override
    protected void paintComponent(final Graphics g) {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        super.paintComponent(g);
        if (this.iconBack == null) {
            this.iconBack = CutButtonImage.getImage("inkImg/newbackground/zdlh.png", 416, 516);
        }
        g.drawImage(this.iconBack.getImage(), 0, 0, 416, 516, (ImageObserver) this);
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(60, 55, 100, 20, 7, 7);
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
        g2d.setColor(color);
        g2d.fill(roundedRectangle);
        g.drawString("您已经炼化了",200,70);
        g.setColor(Color.red);
        g.drawString(count +"",295,70);
        g.setColor(Color.BLACK);
        g.drawString("次" +"",320,70);
        } else {
            super.paintComponent(g);
            if (this.iconBack == null) {
                this.iconBack = CutButtonImage.getImage("inkImg/hongmu/自动炼化面板红木.png", 423, 475);
            }
            g.drawImage(this.iconBack.getImage(), 0, 0, 423, 411, (ImageObserver) this);
            Graphics2D g2d = (Graphics2D) g.create();
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(60, 30, 100, 20, 7, 7);
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
            g2d.setColor(color2);
            g2d.fill(roundedRectangle);
            g.setColor(Color.yellow); //
            g.drawString("您已经炼化了", 200, 50);
            g.setColor(Color.red);
            g.drawString(count + "", 295, 50);
            g.setColor(Color.yellow);
            g.drawString("次" + "", 320, 50);
        }
    }


    public ImageIcon getIconBack() {
        return iconBack;
    }

    public void setIconBack(ImageIcon iconBack) {
        this.iconBack = iconBack;
    }

    public void setPaneList(JScrollPane paneList) {
        this.paneList = paneList;
    }

    public AotoMaticRefiningBtn getAssistantBtn() {
        return assistantBtn;
    }

    public void setAssistantBtn(AotoMaticRefiningBtn assistantBtn) {
        this.assistantBtn = assistantBtn;
    }

    public JScrollPane getPaneList() {
        return paneList;
    }

    public AutoMaticRefiningView getOptionJpanel() {
        return optionJpanel;
    }

    public void setOptionJpanel(AutoMaticRefiningView optionJpanel) {
        this.optionJpanel = optionJpanel;
    }

    public JLabel getDisplaymodetext() {
        return displaymodetext;
    }

    public void setDisplaymodetext(JLabel displaymodetext) {
        this.displaymodetext = displaymodetext;
    }

    public int getLeftFlag() {
        return leftFlag;
    }

    public void setLeftFlag(int leftFlag) {
        this.leftFlag = leftFlag;
    }

    public AotoMaticRefiningBtn getStart() {
        return start;
    }

    public void setStart(AotoMaticRefiningBtn start) {
        this.start = start;
    }

    public List<AttributeVo> getAttributeVoList() {
        return attributeVoList;
    }

    public void setAttributeVoList(List<AttributeVo> attributeVoList) {
        this.attributeVoList = attributeVoList;
    }

    public String[] getLianHua() {
        return lianHua;
    }

    public void setLianHua(String[] lianHua) {
        this.lianHua = lianHua;
    }

    public RichLabel getRichLabel() {
        return richLabel;
    }

    public void setRichLabel(RichLabel richLabel) {
        this.richLabel = richLabel;
    }

    public JLabel getMsgBox() {
        return msgBox;
    }

    public void setMsgBox(JLabel msgBox) {
        this.msgBox = msgBox;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public RoundRectangle2D getRoundedRectangle() {
        return roundedRectangle;
    }

    public void setRoundedRectangle(RoundRectangle2D roundedRectangle) {
        this.roundedRectangle = roundedRectangle;
    }

    public NewPart getPart() {
        return part;
    }

    public void setPart(NewPart part) {
        this.part = part;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
